package priv.pront.code.national.acwing.math;

import java.util.Scanner;

public class A872_最大公约数 {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while(n-- > 0){
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            System.out.println(gcd(a, b));
        }
    }

    /*g*/
    private static int gcd(int a, int b){
        if(a % b == 0){
            return b;
        }
        return gcd(b % a, a);
    }
}
